<template>
  <!-- 核保记录页面 -->
  <div class="fillcontain">
    <el-form :model="searchParams" ref="ruleForm" label-width="100px" class="search_container">
      <el-row>
        <el-col :span="6">
          <el-form-item label="任务号：" class="text_center">
            <el-input v-model="searchParams.taskNo" placeholder="请输入" clearable @keyup.enter.native="searchRecordEnter"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="6" class="text_center">
          <el-form-item label="申请人:">
            <el-input v-model="searchParams.agentNo" placeholder="请输入" clearable @keyup.enter.native="searchRecordEnter"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="6" class="text_center">
          <el-form-item label="申请日期:">
            <el-date-picker  v-model="searchParams.applyDate" type="date" placeholder="选择日期时间"  value-format="yyyy-MM-dd" format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>
        </el-col>

        <el-col :span="6" class="text_center">
          <el-button type="primary" icon="el-icon-search" @click="getList('resetPage')"></el-button>
          <el-button type="primary" plain icon="el-icon-refresh" @click="resetSearch"></el-button>
        </el-col>
      </el-row>
    </el-form>

    <div class="contain">
      <div class="table_container">
        <el-table v-loading="loading" :data="tableData" highlight-current-row min-height="500"
          header-cell-class-name="table-header-class" style="width: 100%">
          <el-table-column min-width="120" property="taskNo" label="任务号" align="center" show-overflow-tooltip>
          </el-table-column>


          <el-table-column min-width="120" property="agentNo" label="申请人" align="center" show-overflow-tooltip>
          </el-table-column>


          <el-table-column min-width="120" property="applyDate" label="申请日期" align="center" show-overflow-tooltip>
          </el-table-column>

          <el-table-column min-width="120" property="currentSteps" label="处理状态" align="center">
            <template slot-scope="scope">
              <div>{{ scope.row.currentSteps == '01' ? '选择体检项' : scope.row.currentSteps == '02' ? "影像提交" :
                scope.row.currentSteps == '03'
                ? 'AI提交' : scope.row.currentSteps == '04' ? '正常输出结论' : '异常输出结论' }}</div>
            </template>
          </el-table-column>

          <el-table-column min-width="120" property="sourceFlag" label="来源" align="center">
            <template slot-scope="scope">
              <div>
                {{ scope.row.sourceFlag == '0' ? '接口调用' : scope.row.sourceFlag == '1' ? "全文匹配" : '精确匹配'}}
              </div>
            </template>
          </el-table-column>

          <el-table-column min-width="120" property="gradedContent" label="体检等级" align="center" show-overflow-tooltip>
          </el-table-column>

          <el-table-column min-width="120" property="underResult" label="核保结论" align="center" show-overflow-tooltip>
          </el-table-column>

          <el-table-column label="操作" align="center" width="180" fixed="right">

            <template slot-scope="scope">
              <div style="display: flex; justify-content: center">
                <span class="handle-btn" @click="viewHttp(scope.row)">查看报文</span>
                <span class="handle-btn" @click="viewDetail(scope.row)">查看详情</span>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-row>
          <el-col :span="24">
            <div class="pagination">
              <el-pagination background v-if='paginations.total > 0' :page-sizes="paginations.pageSizes"
                :page-size="paginations.pageSize" :layout="paginations.layout" :total="paginations.total"
                :current-page='paginations.pageIndex' @current-change='handleCurrentChange'
                @size-change='handleSizeChange'>
              </el-pagination>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <el-dialog title="接口报文" :visible.sync="addProjectVisible" v-if="addProjectVisible" :show-close="false"
      :close-on-click-modal="false" width="80%" center>
      <el-row>
        <el-col :span="12">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>请求报文</span>
            </div>
            <div class="temp_content" style="height: 500px;">
              <el-input disabled type="textarea" rows="27" placeholder="请输入内容" v-model="gptHttpData.reqParams">
              </el-input>
            </div>
          </el-card>
        </el-col>
        <el-col :span="12">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>返回报文</span>
            </div>
            <div class="temp_content" style="height: 500px;">
              <el-input disabled type="textarea" rows="27" placeholder="请输入内容" v-model="gptHttpData.resResult">
              </el-input>
            </div>
          </el-card>
        </el-col>
      </el-row>
      <!-- 按钮 -->
      <span slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="scrpitTemplateSave">保 存</el-button> -->
        <el-button @click="addProjectVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>

</template>

<script>
import {
  getAssistantRecordInfosApi,
} from "@/api/medicalLibrary/assistantRecoed";
import constant from "@/utils/constant";
export default {
  data() {
    return {
      addProjectVisible: false,
      gptHttpData: {
        reqParams: '',
        resResult: '',
      },
      searchParams: {
        taskNo: "", //任务号
        agentNo: "", //申请人
        applyDate: "", //申请日期
      },
      tableData: [],
      loading: false,
      // 分页
      paginations: {
        total: 0, // 总数
        pageIndex: 1, // 当前位于哪页
        pageSize: 10, // 1页显示多少条
        pageSizes: [10, 20, 30, 50], //每页显示多少条
        layout: "total, sizes, prev, pager, next, jumper" // 翻页属性
      },
    };
  },
  activated() {
    this.getList();
  },
  mounted() { },
  methods: {
    searchRecordEnter(){
      console.log('Enter key pressed!');
      this.getList('resetPage')
    },
    // 查询列表
    getList(flag) {
      if (flag) this.paginations.pageIndex = 1
      this.paginations.total = 0
      let params = {
        taskNo: this.searchParams.taskNo,
        agentNo: this.searchParams.agentNo,
        applyDate: this.searchParams.applyDate,
      }
      params.pageNum = this.paginations.pageIndex;
      params.pageSize = this.paginations.pageSize;

      this.$store.dispatch("loading/CHANGE_LOADING", true);
      this.tableData = []
      getAssistantRecordInfosApi(params).then((res) => {
        this.$store.dispatch("loading/CHANGE_LOADING", false);
        if (res.resultCode == constant.SUCCESS) {
          this.tableData = res.data.list || []
          // 页码赋值
          this.paginations.total = res.data.total;
        }
      })
        .catch((err) => {
          this.$store.dispatch("loading/CHANGE_LOADING", false);
        });
    },
    // 清除查询条件
    resetSearch() {
      this.searchParams = {
        taskNo: "", //任务号
        agentNo: "", //申请人
        applyDate: "", //申请日期
      }
      this.getList('resetPage')
    },
    //查看详情
    viewHttp(row) {
      this.gptHttpData.reqParams = row.reqParams
      this.gptHttpData.resResult = row.resResult
      this.addProjectVisible = true;
    },
    // 编辑
    viewDetail(row) {
      this.$router.push({
        path: "/home/maintenance/robouUnderwriting/aiAssistant/assistantRecordDetail", query: { rowData: row }
      })
    },
    // 每页多少条切换
    handleSizeChange(pageSize) {
      this.paginations.pageSize = pageSize;
      this.getList();
    },
    // 上下分页
    handleCurrentChange(page) {
      this.paginations.pageIndex = page;
      this.getList();
    },
  },
};
</script>

<style lang="less" scoped>
.fillcontain {
  padding-bottom: 0;
}

.contain {
  background: #fff;
  padding: 10px;
  margin-bottom: 20px;
}

.pagination {
  padding: 10px 20px;
  text-align: right;
}


.search_container {
  padding: 20px 20px 0 20px;
}

.handle-btn {
  cursor: pointer;
  color: #409eff;
  display: inline-block;
  padding: 0 8px;
}
</style>
